using System;

namespace lucere.toolkit.cache
{
    /// <summary>
    /// Interface for cache implementations.
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <typeparam name="TValue"></typeparam>
    public interface ICache<TKey, TValue> : IDisposable
    {
        /// <summary>
        /// Returns a thread-safe cache backed by the specified cache. 
        /// In order to guarantee thread-safety, all access to the backed cache must
        /// be accomplished through the returned cache.
        /// </summary>
        /// <param name="cache"></param>
        /// <returns></returns>
        ICache<TKey, TValue> GetSynchronizedCache(ICache<TKey, TValue> cache);

        /// <summary>
        /// Puts a (key, value)-pair into the cache.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        void Add(TKey key, TValue value);

        /// <summary>
        /// Returns the value for the given key. 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        TValue this[TKey key] { get; set; }

        /// <summary>
        /// Returns whether the given key is in this cache. 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool ContainsKey(TKey key);
    }
}